package com.bird.utils;

import java.io.IOException;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.jsp.JspException;
import javax.servlet.jsp.PageContext;
import javax.servlet.jsp.tagext.SimpleTagSupport;

import weibo4j.Oauth;

public class LoginTag extends SimpleTagSupport {

	@Override
	public void doTag() throws JspException, IOException {
		 Oauth oauth = new Oauth();
		 PageContext pageContext =  (PageContext) this.getJspContext();  
	     HttpServletRequest request =  (HttpServletRequest) pageContext.getRequest();  
	     String code = request.getParameter("code");
	//    System.out.println(code);
	     if(code!=null){
		 
			try{
				String token = oauth.getAccessTokenByCode(code).getAccessToken();
				request.getSession().setAttribute("token", token);
	//			System.out.println(token);
			} catch (Exception e) {
				e.printStackTrace();
			}
	     }
	}

}
